#include "mainwindow.h"
#include <QApplication>
#include <QSplashScreen>
#include <QTextCodec>
#include <QFile>
#include <QDebug>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
//    a.setFont(QFont("Microsoft Yahei", 11));


    QSplashScreen *splash = new QSplashScreen;
    splash->setPixmap(QPixmap(":/res/fonts/start.png"));
    splash->show();

    // Start photo
    Qt::Alignment pos = Qt::AlignRight| Qt::AlignBottom;
    splash->showMessage(QObject::tr("Loading Settings......."),pos,Qt::white);

    // Set start time
    for(int i=0;i<5000;i++){
        splash->repaint();
    }

    // Load Settings
    QString iniName = QCoreApplication::applicationDirPath() + "/Settings.ini";
    QSettings *iniSetting = new QSettings(iniName,QSettings::IniFormat);
    QString color = iniSetting->value("/THEME/color").toString();
    QString fontsize = iniSetting->value("/THEME/fontsize").toString();
    delete iniSetting;

    // Theme style
    QString style;
    if("Light" == color){
        style = ":/res/light/style.qss";
    }else{
        style = ":/res/dark/style.qss";
    }

    QFile file(style);
    if(file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QString qss = QLatin1String(file.readAll());
        qApp->setStyleSheet(qss);
        file.close();
    }else{
        qDebug() << "Failed to load: " << file.fileName();
    }

    // Set App's icon and name
    MainWindow w;
    QIcon appIcon(":/res/fonts/barchart.png");                       // Get the icon for the right corner
    w.setWindowIcon(appIcon);
    w.setWindowTitle("QMavPlotter (QMP)");
    w.show();


    // Close the start picture
    splash->finish(&w);
    delete splash;


    return a.exec();
}
